package top.mingtea.propertymannagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.mingtea.propertymannagement.pojo.Building;
import top.mingtea.propertymannagement.service.BuildingService;

import java.util.List;

@RestController
@RequestMapping("/Building")
@CrossOrigin
public class BuildingController {
    @Autowired
    private final BuildingService buildingService;

    public BuildingController(BuildingService buildingService) {
        this.buildingService = buildingService;
    }

    @GetMapping("/getlist")
    public List<Building> getAll() {
        return buildingService.getAll();
    }

    @PostMapping("/add")
    public void add(@RequestBody Building building) {
        buildingService.add(building);
    }

    @DeleteMapping("/remove/{id}")
    public void remove(@PathVariable("id") int building_id) {
        buildingService.remove(building_id);
    }

    @PutMapping("/update")
    public void update(@RequestBody Building building) {
        buildingService.update(building);
    }
}
